home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / mslang / poetmf / src / helloapp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-23  |  3.8 KB  |  165 lines

  1. // ******************************************************************
  2. //
  3. //    helloapp.cpp
  4. //
  5. //    Implemented classes:
  6. //        CHelloWinApp
  7. //        CHelloMainWnd
  8. //                   
  9. //    Remarks
  10. //        CHelloWinApp is not generated by ClassWizard
  11. //
  12. //    Author :    Nils Behncke
  13. //            POET Software GmbH, August 1993
  14. //
  15. // ******************************************************************
  16.         
  17. #include <stdafx.h>            //    header to MFC
  18.  
  19.  
  20.  
  21. #include <helloapp.h>         //    header to this file
  22. #include <aboutdlg.h>        //    header to aboutdialog
  23. #include <persdlg.h>        //    header to persondialog
  24. #include <progdlg.h>        //    header to programmerdialog
  25. #include <persqry.h>        //    header to personquerydialog
  26. #include <progqry.h>        //    header to programmerquerydialog
  27.       
  28.       
  29. CHelloWinApp NEAR theApp;    //    instance of application
  30.  
  31.  
  32.  
  33. /////////////////////////////////////////////////////////////////////////////////
  34. // CHelloMainWnd
  35.  
  36.  
  37. CHelloMainWnd::CHelloMainWnd ()
  38. {
  39.     Create( NULL, "Hello POET",WS_OVERLAPPEDWINDOW,rectDefault,    //    create mainwindow with menu
  40.             NULL, MAKEINTRESOURCE (IDR_WINHELLOMENU) );
  41.  
  42. }
  43.  
  44.  
  45. BEGIN_MESSAGE_MAP(CHelloMainWnd, CFrameWnd)
  46.     //{{AFX_MSG_MAP(CHelloMainWnd)
  47.     ON_COMMAND(IDM_ABOUT, OnAbout)
  48.     ON_COMMAND(IDM_PERS_EDIT, OnPersEdit)
  49.     ON_COMMAND(IDM_PROG_EDIT, OnProgEdit)
  50.     ON_COMMAND(IDM_EXIT, OnExit)
  51.     ON_COMMAND(IDM_PERS_QUERY, OnPersQuery)
  52.     ON_COMMAND(IDM_PROG_QUERY, OnProgQuery)
  53.     //}}AFX_MSG_MAP
  54. END_MESSAGE_MAP()
  55.  
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CHelloMainWnd message handlers
  59.  
  60.  
  61. void CHelloMainWnd::OnAbout()
  62. {                             
  63.     int nResult;
  64.  
  65.     CAboutDlg aboutdlg (this);
  66.     nResult = aboutdlg.DoModal ();    //    start dialog
  67.     aboutdlg.EndDialog (nResult);
  68. }
  69.  
  70. void CHelloMainWnd::OnPersEdit()
  71. {               
  72.     int nResult;
  73.  
  74.     CEditPersDlg editpersdlg (this);
  75.     nResult = editpersdlg.DoModal ();    //    start dialog
  76.     editpersdlg.EndDialog (nResult);
  77. }
  78.  
  79. void CHelloMainWnd::OnProgEdit()
  80. {
  81.     int nResult;
  82.  
  83.     CEditProgDlg editprogdlg (this);
  84.     nResult = editprogdlg.DoModal ();    //    start dialog
  85.     editprogdlg.EndDialog (nResult);
  86. }
  87.  
  88. void CHelloMainWnd::OnExit()
  89. {
  90.     if (MessageBox ("Terminate Program","Hello POET",MB_YESNO)==IDYES)
  91.       {
  92.           DestroyWindow ();
  93.       };
  94. }
  95.  
  96. void CHelloMainWnd::OnPersQuery()
  97. {
  98.     int nResult;
  99.     
  100.     CPersQueryDlg persquery (this);
  101.     nResult = persquery.DoModal ();        //    start dialog
  102.     persquery.EndDialog (nResult);
  103. }
  104.  
  105. void CHelloMainWnd::OnProgQuery()
  106. {                                 
  107.     int nResult;
  108.     
  109.     CProgQueryDlg progquery (this);
  110.     nResult = progquery.DoModal ();        //    start dialog
  111.     progquery.EndDialog (nResult);
  112. }
  113.  
  114.  
  115.  
  116. // ******************************************************************
  117. //
  118. //    Implementation of the class CHelloWinApp
  119. //
  120. // ******************************************************************
  121.  
  122. CHelloWinApp::CHelloWinApp ()
  123. {
  124. }
  125.  
  126.  
  127. CHelloWinApp::~CHelloWinApp ()
  128. {
  129.     if (oa->Close()!=0)         // Close database "base"
  130.         ErrorExit ("Cannot close base");
  131.         
  132.     if (oa->DisConnect()!=0)     // Disconnect from server
  133.         ErrorExit ("Can't disconnect the program from the server");
  134.  
  135.     delete oa;
  136. }        
  137.  
  138.  
  139.  
  140. BOOL CHelloWinApp::InitInstance ()
  141. {
  142.     m_pMainWnd = new CHelloMainWnd ();    //    create mainwindow
  143.     m_pMainWnd->ShowWindow (m_nCmdShow);    // show it
  144.     m_pMainWnd->UpdateWindow ();
  145.  
  146.     int err = 0;
  147.     
  148.     oa = new PtBase (); // Instance for POET administration
  149.  
  150.     if ((err=oa->Connect ("LOCAL"))!=0) // Connect to server LOCAL
  151.         ErrorExit ("Can't connect to server");
  152.  
  153.     if ((err=oa->Open ("base"))!=0) // Open database "base"
  154.         ErrorExit ("Cannot open base");        
  155.  
  156.         
  157.     return TRUE;
  158. }
  159.  
  160.  
  161. void CHelloWinApp::ErrorExit (char *error)
  162. {
  163.     m_pMainWnd->MessageBox  ("    Error : " + CString(error) + "     ","Abort program",MB_OK);
  164.     m_pMainWnd->DestroyWindow ();
  165. };